<%
layout("/layouts/platform.html"){
%>
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/platform/sys/role" data-pjax id="goback"><i class="ti-angle-left"></i> 返回</a>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="roleForm" role="form" class="form-horizontal parsley-form" data-parsley-validate
                  action="${base}/platform/sys/role/editDo" method="post">
                <div class="row mb10">
                    <div class="col-lg-12">
                        <div class="form-group has-feedback">
                            <label for="parentId" class="col-sm-2 control-label">所属单位</label>

                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input id="parentId" type="text" class="form-control" placeholder="选择单位or系统角色" disabled
                                           value="<%if(!isEmpty(unit)){%>${unit.name}<%}else{%>系统角色<%}%>" data-parsley-required="true"/>

			                             		<span class="input-group-btn">
			                             			<button type="button" class="btn btn-primary" <%if("sysadmin"!=obj.code&&"public"!=obj.code){%>data-toggle="modal"
                                                            data-target="#dialogSelectParentUnit"<%}%>><i class="ti-plus"></i>选择
                                                    </button>

			                             		</span>
                                </div>
                                <input type="hidden" name="id" value="${obj.id!}">
                                <input type="hidden" name="unitid" value="${obj.unitid!}">
                                <input type="hidden" name="oldCode" value="${obj.code!}">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">角色名称</label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="name" name="name" data-parsley-required="true"  placeholder="角色名称"
                                       maxlength="20" value="${obj.name!}" <%if("sysadmin"==obj.code||"public"==obj.code){%>readonly<%}%>>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="code" class="col-sm-2 control-label">权限标识</label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="code" name="code" data-parsley-required="true"  placeholder="权限标识"
                                       maxlength="50" value="${obj.code!}" <%if("sysadmin"==obj.code||"public"==obj.code){%>readonly<%}%>>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="code" class="col-sm-2 control-label">角色说明</label>

                            <div class="col-sm-8">
                                <input type="text" class="form-control" id="note" name="note" placeholder="角色说明"
                                       maxlength="50" value="${obj.note!}">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-3"></div>
                <div class="col-lg-6">
                    <div class="form-group text-center">
                        <label></label>

                        <div>
                            <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
                        </div>
                    </div>
                </div>
            </form>
        </section>

    </div>
</div>
<a class="exit-offscreen"></a>
<!-- 选择上级单位 -->
<div id="dialogSelectParentUnit" class="modal fade bs-modal-sm" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title">选择上级单位</h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <div id="jsTreeUnit" class="demo"></div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-primary" onclick="selectParentMenu()">确认选择</button>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">
    function initTreeView() {
        $("#jsTreeUnit").jstree({
            plugins: ["wholerow"],
            core: {
                data: {
                    async: true,
                    url: function (node) {
                        return node.id === "#" ? "${base}/platform/sys/role/tree" : "${base}/platform/sys/role/tree?pid=" + node.id
                    }
                },
                multiple: false
            }
        }).on("dblclick.jstree", function (node) {
            selectParentMenu();
        });
    }
    //选择父菜单
    function selectParentMenu() {
        var tree = $.jstree.reference("#jsTreeUnit");
        var node = tree.get_selected(true);
        $("#roleForm #parentId").val(node[0].text);
        $("#roleForm input[name='unitid']").val(node[0].id);
        $("#dialogSelectParentUnit").modal("hide");
    }
    $(document).ready(function () {
        initTreeView();
        myForm.init();
        $('#roleForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    setTimeout(function () {
                        $("#goback").trigger("click");
                    }, 1000);
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });
    });
</script>

<%}%>